package com.dream.style.app.ac.shouye;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dream.style.R;

/**
 * @Created by lincyu
 * @Time: 2018/11/19 22:05
 * @Decs: 类
 */
public class GoodMagActivity extends AppCompatActivity {

    /** 上架 **/
    private TextView has;
    /** 仓库 **/
    private TextView whose;
    /** 滑线 **/
    private View line;
    private ViewGroup.MarginLayoutParams lp;
    private int w;
    private View curView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.good_mag);
        has = findViewById(R.id.has);
        whose = findViewById(R.id.whose);
        line = findViewById(R.id.line);
        has.setSelected(true);
        curView = has;
        w = getResources().getDisplayMetrics().widthPixels / 2;
        getWindow().getDecorView().post(new Runnable() {
            @Override
            public void run() {
                lp = (ViewGroup.MarginLayoutParams) line.getLayoutParams();
                lp.width = (int) (has.getPaint().measureText(has.getText().toString()) + 0.5f);
                lp.leftMargin = (w - lp.width) / 2;
                line.setLayoutParams(lp);
            }
        });

        has.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!v.isSelected()){
                    v.setSelected(true);
                    curView.setSelected(false);
                    curView = v;

                    //這裡切換數據。。。。。
                }
            }
        });
        whose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!v.isSelected()){
                    v.setSelected(true);
                    curView.setSelected(false);
                    curView = v;

                    //這裡切換數據。。。。。
                }
            }
        });

    }
}
